using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using SampleImageGenerator.Core;

namespace SampleImageGenerator.Controls
{
	internal class EngineListenerControl : UserControl
	{
		private IEngine m_engine; 
		
		protected delegate void Action();

		public EngineListenerControl()
		{
			m_engine = new EmptyEngine();
		}
		
		public IEngine Engine 
		{
			get { return m_engine; }

			set
			{
				IEngine oldEngine = m_engine;
				if (oldEngine != null)
				{
					DetachEventHandlers(oldEngine);
				}

				IEngine newEngine = value ?? new EmptyEngine();

				AttachEventHandlers(newEngine);
				UpdateState(newEngine);

				m_engine = newEngine;
			}
		}

		protected virtual void AttachEventHandlers(IEngine engine) { }

		protected virtual void DetachEventHandlers(IEngine engine) { }

		protected virtual void UpdateState(IEngine engine) { }
	}
}